package com.mengxingyun.shortlink.project.mq.producer;

import cn.hutool.core.lang.UUID;
import com.mengxingyun.shortlink.project.dto.biz.ShortLinkStatsRecordDTO;
import lombok.RequiredArgsConstructor;
import org.redisson.api.RBlockingDeque;
import org.redisson.api.RDelayedQueue;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

import static com.mengxingyun.shortlink.project.common.constant.RedisKeyConstant.DELAY_QUEUE_STATS_KEY;

/**
 * @Description: 延迟消费短链接统计发送者
 * @Author: heshen-mengxingyun
 * @Date: 2024/8/9 21:13
 */
@Component
@RequiredArgsConstructor
@Deprecated
public class DelayShortLinkStatsProducer {
    private final RedissonClient redissonClient;

    /**
     * 发送延迟消息短链接统计
     * @param statsRecord
     */
    public void send(ShortLinkStatsRecordDTO statsRecord){
        statsRecord.setMessageId(UUID.fastUUID().toString());
        RBlockingDeque<ShortLinkStatsRecordDTO> blockingDeque = redissonClient.getBlockingDeque(DELAY_QUEUE_STATS_KEY);
        RDelayedQueue<ShortLinkStatsRecordDTO> delayedQueue = redissonClient.getDelayedQueue(blockingDeque);
        delayedQueue.offer(statsRecord, 5, TimeUnit.SECONDS);
    }
}
